import { createApp } from 'vue'
import pinia from './stores'
// import { createPinia } from 'pinia'
import router from '@/router'
import App from './App.vue'

import '@/styles/index.scss'
import 'element-plus/dist/index.css'
import * as ElementPlusIconsVue from '@element-plus/icons-vue'

import 'virtual:windi.css'

// 第一步：创建并初始化 pinia
// const pinia = createPinia()

const app = createApp(App)

app.use(pinia)
// 确定是否有激活的 pinia 实例 后再 加载router
import { getActivePinia } from 'pinia'
const activePinia = getActivePinia()
if (!activePinia) {
  console.error('请确保在调用此代码之前已经调用了 app.use(pinia)')
} else {
  app.use(router)
}

// 导入所有图标并进行全局注册
// 自动按需导入图标使用方式会变，i-ep-icon-name ,传统的使用方式会失效
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
  app.component(key, component)
}

// 路由守卫拦截 全局前置守卫
// import './utils/permission'
// 权限控制
import permission from './directives/permission'
app.use(permission)

app.mount('#app')
